﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FighterClubZero
{
    public partial class Launcher : Form
    {
        public Launcher()
        {
            InitializeComponent();
        }

        private void Launcher_Load(object sender, EventArgs e)
        {
            bool installFlag = SEUtils.checkSoftEtherIsInstalled();
            if (!installFlag)
            {
                DialogResult dr = MessageBox.Show("SE网卡未安装", "点击确定开始安装", MessageBoxButtons.OK);
                if (dr == DialogResult.OK)
                {
                    Process proc = null;
                    try
                    {
                        //string targetDir = string.Format(@"D:\adapters\setup");//this is where mybatch.bat lies
                        proc = new Process();
                        //proc.StartInfo.WorkingDirectory = targetDir;
                        proc.StartInfo.FileName = ".\\安装网卡.bat";
                        proc.StartInfo.Arguments = string.Format("10");//this is argument
                        proc.StartInfo.CreateNoWindow = false;
                        proc.Start();
                        proc.WaitForExit();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception Occurred :{0},{1}", ex.Message, ex.StackTrace.ToString());
                    }
                }
            }
        }

        private void Launcher_Shown(object sender, EventArgs e)
        {
            bool installFlag = SEUtils.checkSoftEtherIsInstalled();
            if (!installFlag)
            {
                System.Environment.Exit(0);
            }
            else {
                ServiceController ctl = SEUtils.getSeVpnService();
                //检测sevpn服务是否开启
                if (ctl.Status != ServiceControllerStatus.Running)
                {
                    ctl.Start();
                    Thread.Sleep(500);
                }
                Form1 frm1 = new Form1();
                frm1.Show();
                this.Hide();
            }
        }
    }
}
